package com.hsgene.order.dto.pre;

import com.hsgene.common.util.exception.IllegalParamException;
import com.hsgene.common.util.validation.FieldChecker;
import com.hsgene.order.constants.DeliveryType;
import com.hsgene.order.constants.PayType;
import com.hsgene.order.dto.OrderMallDiscountDto;
import com.hsgene.order.dto.OrderMallInvoiceDto;
import com.hsgene.user.dto.address.ConsignAddressDto;
import org.springframework.util.CollectionUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
 * 预订单信息
 *
 * @author wangbing
 * @version 1.0, 2018/8/6
 */
public class PreOrderDto implements Serializable {

    private static final long serialVersionUID = -28794144845111458L;
    /**
     * 总订单id
     */
    private String id;

    /**
     * 用户id
     */
    private String userId;

    /**
     * 订单来源
     */
    private String from;

    /**
     * 订单总金额
     */
    private BigDecimal totalAmount;

    /**
     * 订单优惠总金额
     */
    private BigDecimal totalDiscountsAmount;

    /**
     * 订单实际待支付金额
     */
    private BigDecimal totalRealAmount;

    /**
     * 支付方式
     */
    private String payType;

    /**
     * 投递类型-投递时间段选择
     */
    private String deliveryType;

    /**
     * 收货地址信息
     */
    private ConsignAddressDto consignAddress;

    /**
     * 检测单
     */
    private String detectionImages;

    /**
     * 采样信息
     */
    private String sampleImages;

    /**
     * 内推医生编号
     */
    private String twitterDoctor;

    /**
     * 内推地服编号
     */
    private String twitterEmployee;

    /**
     * 是否需要开具发票
     */
    private Boolean needInvoice;

    /**
     * 预订单商品信息
     */
    private List<PreOrderItemDto> items;

    /**
     * 总订单的优惠信息
     */
    private List<OrderMallDiscountDto> discounts;

    /**
     * 订单发票信息
     */
    private OrderMallInvoiceDto invoice;

    public void check() {
        FieldChecker.checkEmpty(id, "id");
        FieldChecker.checkEmpty(userId, "userId");
        FieldChecker.checkEmpty(from, "from");

        PayType payType = PayType.getEnum(this.getPayType());
        /*if (PayType.UNDEFINED.equals(payType)) {
            throw new IllegalParamException("不支持的支付方式：" + this.getPayType());
        }*/
        DeliveryType deliveryType = DeliveryType.getEnum(this.getDeliveryType());
        if (DeliveryType.UNDEFINED.equals(deliveryType)) {
            throw new IllegalParamException("不支持的投递时间段选择：" + this.getDeliveryType());
        }
        FieldChecker.checkEmpty(consignAddress, "收货地址信息");
        consignAddress.simpleCheck();
        if (needInvoice) {
            FieldChecker.checkEmpty(invoice, "发票信息");
            invoice.simpleCheck();
        }
        if (!CollectionUtils.isEmpty(discounts)) {
            discounts.forEach(OrderMallDiscountDto::simpleCheck);
        }
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getFrom() {
        return from;
    }

    public void setFrom(String from) {
        this.from = from;
    }

    public BigDecimal getTotalAmount() {
        return totalAmount;
    }

    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }

    public BigDecimal getTotalDiscountsAmount() {
        return totalDiscountsAmount;
    }

    public void setTotalDiscountsAmount(BigDecimal totalDiscountsAmount) {
        this.totalDiscountsAmount = totalDiscountsAmount;
    }

    public BigDecimal getTotalRealAmount() {
        return totalRealAmount;
    }

    public void setTotalRealAmount(BigDecimal totalRealAmount) {
        this.totalRealAmount = totalRealAmount;
    }

    public String getPayType() {
        return payType;
    }

    public void setPayType(String payType) {
        this.payType = payType;
    }

    public String getDeliveryType() {
        return deliveryType;
    }

    public void setDeliveryType(String deliveryType) {
        this.deliveryType = deliveryType;
    }

    public ConsignAddressDto getConsignAddress() {
        return consignAddress;
    }

    public void setConsignAddress(ConsignAddressDto consignAddress) {
        this.consignAddress = consignAddress;
    }

    public Boolean getNeedInvoice() {
        return needInvoice;
    }

    public void setNeedInvoice(Boolean needInvoice) {
        this.needInvoice = needInvoice;
    }

    public List<PreOrderItemDto> getItems() {
        return items;
    }

    public void setItems(List<PreOrderItemDto> items) {
        this.items = items;
    }

    public List<OrderMallDiscountDto> getDiscounts() {
        return discounts;
    }

    public void setDiscounts(List<OrderMallDiscountDto> discounts) {
        this.discounts = discounts;
    }

    public OrderMallInvoiceDto getInvoice() {
        return invoice;
    }

    public void setInvoice(OrderMallInvoiceDto invoice) {
        this.invoice = invoice;
    }

    public String getDetectionImages() {
        return detectionImages;
    }

    public void setDetectionImages(String detectionImages) {
        this.detectionImages = detectionImages;
    }

    public String getSampleImages() {
        return sampleImages;
    }

    public void setSampleImages(String sampleImages) {
        this.sampleImages = sampleImages;
    }

    public String getTwitterDoctor() {
        return twitterDoctor;
    }

    public void setTwitterDoctor(String twitterDoctor) {
        this.twitterDoctor = twitterDoctor;
    }

    public String getTwitterEmployee() {
        return twitterEmployee;
    }

    public void setTwitterEmployee(String twitterEmployee) {
        this.twitterEmployee = twitterEmployee;
    }
}
